import request from '@/utils/request'
// 用户登录，获取信息等需要的接口
// 加密方法
import {
  RSAencrypt
} from '@/utils/RAS.js'

// 验证用户是否注册过
export const userIsRes = (params) => {
  // type: 'register' // 注册字段
  // type: 'retrieve' ,// 找回字段
  // type:'modifyEmail'//更换字段
  return request({
    method: 'get',
    url: '/account/iphoneOrEmail',
    params
  })
}




// 邮箱验证码发送
export const emailRegister = (data) => {
  // type: 'register' // 注册字段
  // type: 'retrieve' ,// 找回字段
  // type:'modifyEmail'//更换字段
  return request({
    method: 'POST',
    url: 'account/emailRegister',
    data: data
  })
}
// 手机验证码发送
export const smsRegister = (data) => {
  // type: 'register' // 注册字段
  // type: 'retrieve' ,// 找回字段
  // type:'modifyMobile'//更换字段
  return request({
    method: 'POST',
    url: 'account/smsRegister',
    data: data
  })
}
// 邮箱注册/手机注册接口
export const register = (data) => {
  return request({
    method: 'POST',
    url: 'account/register',
    data: { ...data,
      pwd: RSAencrypt(data.pwd)
    }
  })
}

// 生成私钥和公钥
export const createSecretKey = (params) => {
  return request({
    params,
    method: 'get',
    url: 'asaSecretKey/createSecretKey'
  })
}

// 绑定密钥
export const bindModify = (data) => {
  return request({
    method: 'post',
    url: 'asaSecretKey/modify',
    data: data
  })
}
// 绑定邮箱或者手机号
export const modifyUserAccount = (data) => {
  return request({
    method: 'post',
    url: 'userInfo/modifyUserAccount',
    data: data
  })
}

// 修改用户信息、
export const editModifyUser = (data) => {
  return request({
    method: 'post',
    url: 'userInfo/modifyUser',
    data: data
  })
}

// 登录
export const login = (data) => {
  return request({
    method: 'POST',
    url: 'account/login',
    data: { ...data,
      pwd: RSAencrypt(data.pwd)
    }
  })
}

//图像上传
export const uploadImg = (data) => {
  return request({
    method: 'POST',
    headers: {
      "Content-Type": "multipart/form-data"
    },
    url: 'fdfs/upload',
    data: data
  })
}


// 找回密码
export const retrievePwd = (data) => {
  return request({
    method: 'POST',
    url: 'account/retrievePwd',
    data: { ...data,
      pwd: RSAencrypt(data.pwd)
    }
  })
}
// 获取图片验证码
export const createCode = () => {
  return request({
    method: 'get',
    responseType: 'blob',
    url: 'account/createCode'
  })
}
// 验证图片验证码是否正确
export const userCode = (userCode) => {
  return request({
    method: 'get',
    url: `account/isCode?userCode=${userCode}`
  })
}

// 查看是否是第一次登陆
export const findCampaignCount = (type) => {

  return request({
    method: 'get',
    url: '/campaign/findCampaignCount?currencyType=' + type
  })
}


// 查看是否是第一次登陆
export const infoGathering = (data) => {
  return request({
    method: 'post',
    url: 'comsumer/infoGathering',
    data
  })
}
// 微信登录查看是否有绑定手机号
export const weixinlogin = (params) => {
  return request({
    method: 'get',
    url: 'account/weixinlogin',
    params
  })
}

// 检测是否绑定微信
export const isBindWeixin = (params) => {
  return request ({
    method: 'get',
    url: 'wechat/login/result',
    params
  })
}
// 微信登录二维码url
export const weixinURL = (params) => {
  return request ({
    method: 'get',
    url: '/wechat/getWechatLoginQrcode',
    params
  })
}
// 微信登录绑定已有账号
export const upWeixinUser = (data) => {
  return request({
    method: 'post',
    url: 'account/upWeixinUser',
    data:{...data,pwd:RSAencrypt(data.pwd)}
  })
}

// 获取用户信息
export const getInfo = (params) => {
  return request({
    params,
    method: 'get',
    url: '/userInfo/findUser'
  })
}

// 修改用户密码
export const editUserPass = (data) => {
  return request({
    method: 'post',
    url: '/userInfo/modifyPwd',
    data:{newPwd:RSAencrypt(data.newPwd),oldPwd:RSAencrypt(data.oldPwd)}
  })
}

// 更改手机号或者邮箱
export const editTelEmail = (data) => {
  return request({
    method: 'post',
    url: '/userInfo/modifyAccount',
    data
  })
}

// 操作日志
export const findOpeation = (params) => {
  return request({
    params,
    method: 'get',
    url: 'operLog/find'
  })
}

export const findOpeationUserId = (params) => {
  return request({
    params,
    method: 'get',
    url: '/operLog/findUserId'
  })
}
export const bindTelEmail = (data) => {
  return request({
    method: 'post',
    url: '/userInfo/modifyUserAccount',
    data
  })
}

// 权限明细
export const permission = (params) => {
  return request({
    method: 'get',
    url: '/sysUserRole/findRoleDetails',
    params
  })
}

// 删除 证书
export const delZS = (params) => {
  return request({
    params,
    method: 'get',
    url: '/secretAccount/remove'
  })
}

/* 微信 */


// 获取微信文章列表
export const findBatchgetMaterial = (params) => {
  return request({
    params,
    method: 'get',
    url: '/account/findBatchgetMaterial'
  })
}


// 获取微信文章详情
export const findMaterial = (params) => {
  return request({
    params,
    method: 'get',
    url: '/account/findMaterial'
  })
}

// 查询某一个用户
export const findOneUser = (data) => {
  return request({
    data,
    method: 'post',
    url: '/msg/find'
  })
}

// 查询权限角色列表
export const findRoleList = (params) => {
  return request({
    params,
    method: 'get',
    url: '/sysUserRole/findRoleList'
  })
}


// 邀请某个用户称为下级角色
export const msgAdd = (data) => {
  return request({
    data,
    method: 'post',
    url: '/msg/add'
  })
}


// 拒绝或接受邀请
export const msgModify = (data) => {
  return request({
    data,
    method: 'post',
    url: '/msg/modify'
  })
}


// 修改下级角色信息
export const managerModify = (data) => {
  return request({
    data,
    method: 'post',
    url: '/userManager/modify'
  })
}

// 删除下级角色信息
export const managerRemove = (data) => {
  return request({
    data,
    method: 'post',
    url: '/userManager/remove'
  })
}


// 查询用户的下级用户
export const userManagerFindUser = (params) => {
  return request({
    params,
    method: 'get',
    url: '/userManager/findUser'
  })
}
